var basePath="http://localhost:8080/";

function changeValidateCode(obj) {
    obj.src = basePath + "authentication/code/image?"+Math.random();
}


function pwdLogin(){
    var is_start=$('input[name=is_start]').val();
    var name = $('#name').val();
    var pwd = $('#pwd').val();
    var imageCode = $('#validateCode').val();

    if(name == ''){
        layer.tips('请填写邮箱/用户名/手机号', '#name',{
            tips:[2,'#f29202']
        });
        return false;
    }
    if(pwd == ''){
        layer.tips('请填写密码', '#pwd',{
            tips:[2,'#f29202']
        });
        return false;
    }
    if(imageCode == ''){
        layer.tips('请填写验证码','#validateCode',{tips:[2,'#f29202']});
        return false;
    }

    $.ajax({
        url:basePath + "user/login",
        // headers : {'Content-Type':'application/x-www-form-urlencoded'},
        type: "POST",
        dataType: "json",
        data:{"username":name,"password":pwd,"imageCode":imageCode},
        success: function (data) {
            console.log(data)
            if (data.status == 200){
                location.href = 'index.html';
            }else if(data.msg == '验证码不存在' || data.msg == '验证码不匹配'){
                layer.tips('验证码错误','#validateCode',{tips:[4,'#f29202']});
            }else if (data.msg == '验证码已过期'){
                layer.tips('超时，请刷新验证码','#validateCode',{tips:[4,'#f29202']});
            }else if(data.msg == 'user does not exist'){
                layer.tips('用户不存在', '#name',{tips:[4,'#f29202']});
            }else if(data.msg = 'password does not match stored value'){
                layer.tips('密码错误', '#pwd',{tips:[4,'#f29202']});
            }

        }
    })
}

